<div id="forum_left_content">

       <div id="forum_topic">


        <?php

        //get forum id from URL using $_GET global variable
        $forum_id = $_GET['forum'];


        mysql_connect("localhost","root","");
        mysql_select_db("susudo");

        $select_forum_query="SELECT *, forum.id as forum_id FROM forum JOIN users_profile ON forum.user_id = users_profile.user_id where forum.id = $forum_id ORDER BY created_at DESC ";

        $forums= mysql_query($select_forum_query);

        if ($forums){
        while ($row = mysql_fetch_assoc($forums)) {

            ?>


        <div class="forum_post">
            <h1><a href="frontend.php?page=comment&forum=<?php echo $row["forum_id"];?>"><?php echo $row['forum_topic']; ?></a></h1>
            <h2><?php echo $row['forum_content']; ?></h2>

            <div id="comment_author">
                Created by: <a href=""><?php echo $row["first_name"]." ". $row["mid_name"]." ".$row["last_name"]; ?></a> &nbsp|&nbsp <a href="frontend.php?page=comment&forum=<?php echo $row["forum_id"];?>"> Comments</a>:23</br>

            </div>
            <div class="separator"></div>
        </div>


        <?php } ?>


        
        <?php } else { ?>
         No post found!
        <?php } ?>


    </div>

    <?php

    mysql_connect("localhost","root","");
    mysql_select_db("susudo");

    
    $select_comment_query="SELECT * FROM comment JOIN users ON comment.user_id = users.id where comment.forum_id = $forum_id  ORDER BY comment.created_at DESC ";
    $comments= mysql_query($select_comment_query);

    if ($comments) {
        while ($row = mysql_fetch_assoc($comments)) {
            ?>
    <div class="comment">
        <h1><a href=""><?php echo $row['forum_topic']; ?></a></h1>
        <h2><?php echo $row['comment_text']; ?></h2>

        <div class="comment_author">
                Commented by: <a href=""><?php echo $row["username"]; ?></a> | On <?php echo date("F j Y", $row['created_at']);?></br>

            </div>
            <div class="separator"></div>

    </div>


        <?php }} ?>



        <div id="add_comment">
            <form method="post" action="<?php echo "$action_path/insert_comment_action.php"; ?>" >
                <!-- now pass the forum id to comment insert action -->
                <input type="hidden" name="forum_id" value="<?php echo $forum_id;?>" />

                <h1>Your Comment:</h1><br/><textarea name="comment_text" rows="4" cols="90" ></textarea><br/>
                <input type="submit" value="Post">
            </form>
        </div>
</div>